Skip to content

Conversation

@TirthDhandhukia30
Copy link

@TirthDhandhukia30 TirthDhandhukia30 commented Oct 16, 2025

#38

Theme Toggle FOUC Fix

Problem

The dark mode/light mode theme toggle button appeared large and unstyled during initial page load on slow network connections, causing a "Flash of Unstyled Content" (FOUC).

Root Cause

The theme toggle button was rendering before the main CSS stylesheet (global.css) loaded. This caused the SVG icons to display at their default size without proper styling, creating a jarring visual experience.

  • Added critical inline CSS in BaseLayout.astro to style theme toggle immediately
  • Enhanced ThemeSwitcher skeleton state with proper sizing to prevent layout shift
  • Added id='theme-switcher-container' and 'theme-active' class for CSS targeting
  • Ensures theme toggle appears correctly sized from first paint
  • Prevents Flash of Unstyled Content (FOUC) on slow network connections
  • Includes comprehensive documentation in FOUC_FIX.md

- Added critical inline CSS in BaseLayout.astro to style theme toggle immediately
- Enhanced ThemeSwitcher skeleton state with proper sizing to prevent layout shift
- Added id='theme-switcher-container' and 'theme-active' class for CSS targeting
- Ensures theme toggle appears correctly sized from first paint
- Prevents Flash of Unstyled Content (FOUC) on slow network connections
- Includes comprehensive documentation in FOUC_FIX.md
@lovestaco
Copy link
Contributor

Hi thanks for the PR, will check in a while

<div id="theme-switcher-container" className="grid grid-cols-1">
<div className="relative z-0 inline-grid grid-cols-2 gap-0.5 rounded-full bg-gray-950/5 p-0.5 sm:p-0.75 text-gray-950 dark:bg-white/10 dark:text-white">
<div className="relative rounded-full p-0.5 sm:p-1 lg:p-1 theme-active">
<svg viewBox="0 0 28 28" fill="none" className="size-4 sm:size-5 lg:size-6">
Copy link
Contributor

@lovestaco lovestaco Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is hardcoding the svg in file required? We have many lucide icons,
if its absolutely required, pls put it in public dir and use its url
<img src="/freedevtools/svg_icons/comet/moon.svg">

Ex: https://hexmos.com/freedevtools/svg_icons/comet/moon.svg

FOUC_FIX.md Outdated
The dark mode/light mode theme toggle button appeared large and unstyled during initial page load on slow network connections, causing a "Flash of Unstyled Content" (FOUC).

## Root Cause
The theme toggle button was rendering before the main CSS stylesheet (`global.css`) loaded. This caused the SVG icons to display at their default size without proper styling, creating a jarring visual experience.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add the description in PR itself and rm this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants